import requests
from requests.exceptions import ReadTimeout, ConnectionError, RequestException
import re
import json
url_string = 'https://s.taobao.com/search?q=%E6%89%8B%E6%9C%BA&imgfile=&js=1&stats_click=search_radio_all%3A1&initiative_id=staobaoz_20180824&ie=utf8'
header = {
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6)'
}

try:
    with requests.get(url_string, headers=header) as f:
        if f.status_code == requests.codes.ok:
            # print(f.text)
            html = f.text
            content = re.findall(r'g_page_config = (.*?) g_srp_loadCss', html, re.S)[0].strip()[:-1]

            print(json.loads(content))
        else:
            print('Stats:', f.status_code, f.reason)
except ReadTimeout:
        print('Time Out')
except ConnectionError:
        print('Connection Error')
except RequestException:
        print('Request Error')